Ext.define('Jason.view.protal.authentication.Login', {
    extend: 'Jason.view.protal.authentication.LockingWindow',
    xtype: 'pageslogin',
	alternateClassName : 'pageslogin',
    requires: [
        'Ext.Component',
        'Jason.view.protal.authentication.AuthenticationModel',
        'Jason.view.protal.authentication.Dialog',
        'Ext.container.Container',
        'Ext.form.field.Text',
        'Wys.locale.Locale',
        'Jason.store.ReqUrl',
        'Ext.form.field.Checkbox',
        'Ext.button.Button'
    ],

    title: I18N.LoginTitle,
    defaultFocus: 'authdialog', // Focus the Auth Form to force field focus as well
    items: [
        {
            xtype: 'authdialog',
            defaultButton : 'loginButton',
            autoComplete: true,
            bodyPadding: '20 20',
            cls: 'auth-dialog-login',
            header: false,
            width: 415,
            layout: {
                type: 'vbox',
                align: 'stretch'
            },

            defaults : {
                margin : '5 0'
            },

            items: [
                {
                    xtype: 'label',
                    text: I18N.LoginLabel
                },
                {
                    xtype: 'textfield',
                    cls: 'auth-textbox',
                    name: 'userid',
                    bind: '{userid}',
                    height: 55,
                    hideLabel: true,
                    allowBlank : false,
                    emptyText: I18N.UserId,
                    listeners : {
                    	specialkey : function(field,e){
                    		if (e.getKey()==Ext.EventObject.ENTER){
                    			field.up().down('textfield[name=password]').focus(true,false);
                    		}
                    	}
                    },
                    triggers: {
                        glyphed: {
                            cls: 'trigger-glyph-noop auth-email-trigger'
                        }
                    }
                },
                {
                    xtype: 'textfield',
                    cls: 'auth-textbox',
                    height: 55,
                    hideLabel: true,
                    emptyText: I18N.Password,
                    inputType: 'password',
                    name: 'password',
                    bind: '{password}',
                    allowBlank : false,
                    listeners : {
                    	specialkey : function(field,e){
                    		if (e.getKey()==Ext.EventObject.ENTER){
                    			var loginBtn = field.up().lookupReference('loginButton');
                    			loginBtn.fireEvent('click',loginBtn);
                    		}
                    	}
                    },
                    triggers: {
                        glyphed: {
                            cls: 'trigger-glyph-noop auth-password-trigger'
                        }
                    }
                },{
                    xtype: 'textfield',
                    cls: 'auth-textbox',
                    height: 55,
                    hideLabel: true,
                    emptyText: I18N.DynamicCode,
                    maxLength:10,
                    inputType: 'dynamicCode',
                    name: 'dynamicCode',
                    listeners : {
                    	render : function(field){
                    		var me = this;
                    		Ext.defer(function(){
                    			field.setHidden(session.get('userKeyPlateLogin') === 'true');
                    			field.allowBlank = (session.get('userKeyPlateLogin') === 'true');
                    		},1000);
                    	},
                    	specialkey : function(field,e){
                    		if (e.getKey()==Ext.EventObject.ENTER){
                    			var loginBtn = field.up().refs.loginButton;
                    			loginBtn.fireEvent('click',loginBtn);
                    		}
                    	}
                    },
                    triggers: {
                        glyphed: {
                            cls: 'trigger-glyph-noop auth-password-trigger'
                        }
                    }
                },
                {
                    xtype: 'container',
                    layout: 'hbox',
                    items: [
                        {
                            xtype: 'checkboxfield',
                            flex : 1,
                            reference : 'remeberCheckBox',
                            cls: 'form-panel-font-color rememberMeCheckbox',
                            height: 30,
                            listeners : {change:'onPersistChange'},
                            bind: '{persist}',
                            boxLabel: I18N.RememberMe
                        },
                        {
                            xtype: 'box',
                            hidden:true,
                            html: '<a href="#authentication.passwordreset" class="link-forgot-password"> 找回密码 ?</a>'
                        }
                    ]
                },
                {
                    xtype: 'button',
                    reference: 'loginButton',
                    scale: 'large',
                    ui: 'soft-green',//
//                    ui:'soft-unifiedLogin',
                    iconAlign: 'right',
                    iconCls: 'x-fa fa-angle-right',
                    text: I18N.LoginTitle,
                    formBind: true,
                    listeners: {
                        click: 'onLoginButton'
                    }
                },
                {
                    xtype: 'box',
                    html: '<div class="outer-div"><div class="seperator">或</div></div>',
                    margin: '10 0'
                },
                {
                    xtype: 'button',
                    scale: 'large',
                    ui: 'soft-blue',
                    iconAlign: 'right',
                    iconCls: 'x-fa fa-facebook',
                    text: '使用Facebook登录',
                    listeners: {
                        click: 'onFaceBookLogin'
                    }
                },
                {
                    xtype: 'box',
                    html: '<div class="outer-div"><div class="seperator">或</div></div>',
                    margin: '10 0'
                },
                {
                    xtype: 'button',
                    scale: 'large',
                    ui: 'gray',
                    iconAlign: 'right',
                    iconCls: 'x-fa fa-user-plus',
                    text: '创建一个新的帐号',
                    listeners: {
                        click: 'onNewAccount'
                    }
                }
            ]
        }
    ],

    initComponent: function() {
        this.addCls('user-login-register-container');
        this.callParent(arguments);
    }
});
